package com.palmar.proxy.initial;

import com.palmar.proxy.handler.socks.SocksAuthSelectorHandler;
import com.palmar.proxy.handler.socks.SocksAuthenticationHandler;
import com.palmar.proxy.handler.socks.SocksCommandHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.socksx.v5.*;

/**
 * Socks代理初始化
 */
public class SocksProxyChannelInitializer extends ChannelInitializer {



    @Override
    protected void initChannel(Channel channel) throws Exception {
        channel.pipeline().addLast(new Socks5ServerEncoder(Socks5AddressEncoder.DEFAULT));
        channel.pipeline().addLast(new Socks5InitialRequestDecoder());
        channel.pipeline().addLast(new SocksAuthSelectorHandler());//认证协商
        channel.pipeline().addLast(new Socks5PasswordAuthRequestDecoder());
        channel.pipeline().addLast(new SocksAuthenticationHandler());//密码认证
        channel.pipeline().addLast(new Socks5CommandRequestDecoder());
        channel.pipeline().addLast(new SocksCommandHandler());
    }
}
